<template>
  <fieldset>
    <legend>商品</legend>
    <h1>{{ name }}</h1>
    <ul>
      <li v-for="item in data" :key="item.id">
        <b>产品名称：{{ item.title }}</b>
        ------
        <b>产品价格：{{ item.price }}</b>
        ------
        <b>产品库存：{{ item.inventory }}</b>
        ------
        <button @click="addCart(item)">加入购物车</button>
      </li>
    </ul>
  </fieldset>
</template>
<script setup>
import { cart } from '../store/cart'
import { storeToRefs } from 'pinia'
let cartStore = cart()
let { data, name } = storeToRefs(cartStore)
console.log(data)
cartStore.feachData()

let addCart = (current) => {
  cartStore.add(current)
}
</script>
